/**
 * Copyright 2008 floop.pl
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 **/
package org.eaicompiler.util;

import org.eaicompiler.antlr.exceptions.InvalidArgumentException;
import org.eaicompiler.model.Defines;

/**
 * Various utility functions for parser
 * 
 * @author floop.pl
 */
public class Util {
	private static Defines defines = new Defines();

	public static void validatePercent(int v) {
		if (v < -100 || v > 100) {
			throw new InvalidArgumentException("Percentage value " + v + " is not between 0 and 100");
		}
	}

	public static int makeTime(int time, String suffix) {
		if ("s".equals(suffix)) {
			time = time * 1000;
		}
		return time;
	}

	public static String unQuoteString(String s) {
		return s.substring(s.indexOf('"') + 1, s.lastIndexOf('"'));
	}

	public static int resolve(int definesType, String define)
	{
		return defines.resolve(definesType, define);
	}

	public static void define (int definesType, String define, int value)
	{
		defines.define(definesType, define, value);		
	}	
}
